<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>出库单打印</title>
    <link rel="stylesheet" href="/layui/css/layui.css">
    <style>
        @media print {
            .no-print, .layui-layout-admin .layui-header, .layui-layout-admin .layui-side {
                display: none;
            }
            .layui-container {
                width: 100%;
                padding: 0;
            }
            .print-title {
                text-align: center;
                margin: 20px 0;
                font-size: 24px;
            }
        }
        table thead th {
            background-color: green;
            color: white;
        }
    </style>
</head>
<body>
<div class="layui-container layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">小药店管理系统</div>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a>
                    <img src="//unpkg.com/outeres@0.0.10/img/layui/icon-v2.png" class="layui-nav-img">
                    欢迎, <span id="username">管理员</span>
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" onclick="logout()">退出</a></dd>
                </dl>
            </li>
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">采购管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/supplier/supplier.html">供应商信息管理</a></dd>
                        <dd><a href="/supplier/drug.html">药品信息管理</a></dd>
                        <dd><a href="/procurement/add.html">采购单添加</a></dd>
                        <dd><a href="/procurement/list.html">采购单管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">销售管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/sales/add_xiaoshoudan.html">销售单添加</a></dd>
                        <dd><a href="/sales/xiaoshoumingxi.html">销售单管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">药店统计管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/statistics/instock.html">入库统计</a></dd>
                        <dd><a href="/statistics/sales.html">销售统计</a></dd>
                        <dd><a href="/statistics/stock.html">库存查询</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">人事管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/yuangong/add_yuangong.html">员工添加</a></dd>
                        <dd><a href="/yuangong/yuangong.html">员工管理</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">打印管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/print/ruku.html">入库单</a></dd>
                        <dd><a href="/print/chuku.html">出库单</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">系统管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="/user/xiuGaiMiMa.html">修改密码</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <div class="layui-row">
            <div class="layui-col-md12">
                <h2 class="layui-text">首页/出库单</h2>
                <button class="layui-btn layui-btn-normal" style="float: right; margin: 0 0 15px 15px;" onclick="window.print()">打印</button>
                <table class="layui-table" lay-size="sm">
                    <thead>
                    <tr>
                        <th>销售单单号</th>
                        <th>销售时间</th>
                        <th>药品总价格</th>
                        <th>负责人</th>
                        <th>销售单备注</th>
                    </tr>
                    </thead>
                    <tbody id="dataTable"></tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<script src="/layui/layui.js"></script>
<script>
    layui.use(['jquery', 'layer'], function(){
        var $ = layui.$;
        var layer = layui.layer;

        // 设置导航栏选中状态
        $('.layui-nav-item').removeClass('layui-nav-itemed');
        $('dd').removeClass('layui-this');
        var $printNav = $('a:contains("打印管理")').parent();
        $printNav.addClass('layui-nav-itemed');
        $('a:contains("出库单")').parent().addClass('layui-this');

        // 获取出库单数据
        $.ajax({
            url: '/print/stockOut',
            type: 'GET',
            success: function(res){
                var html = '';
                res.forEach(function(item){
                    html += '<tr>' +
                        '<td>' + (item.orderNo || '--') + '</td>' +
                        '<td>' + (item.saleTime || '--') + '</td>' +
                        '<td>' + (item.totalPrice || '--') + '</td>' +
                        '<td>' + (item.operator || '--') + '</td>' +
                        '<td>' + (item.remark || '--') + '</td>' +
                        '</tr>';
                });
                $('#dataTable').html(html);
            },
            error: function() {
                layer.msg('服务器错误，请稍后重试');
            }
        });
    });

    // 退出功能
    function logout() {
        layui.use(['jquery', 'layer'], function(){
            var $ = layui.$;
            var layer = layui.layer;
            
            $.ajax({
                url: '/user/logout',
                type: 'GET',
                success: function(res) {
                    if(res.code === 0) {
                        window.location.href = '/login/login.html';
                    } else {
                        layer.msg(res.msg || '退出失败', {icon: 2});
                    }
                },
                error: function() {
                    layer.msg('服务器错误', {icon: 2});
                }
            });
        });
    }
</script>
</body>
</html>
